home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2007 December / PCWKCD1207B.iso / Blogowanie poza sfera / Scribefire-1.4.2 / scribefire-1.4.2-fx+fl.xpi / chrome / content / accountwizard.js next >
Encoding:
Text File  |  2007-07-23  |  31.6 KB  |  848 lines

  1. var gBlogObject = null;
  2. var gTempBlogObject = new Object();
  3. var gPffAccountTimeOut = [];
  4. var gTempFeedback = null;
  5. var gAutoReturn = false;
  6. var gSelectedBlogs = [];
  7.  
  8. var gPffDebugTemp = [];
  9.  
  10. window.addEventListener('load', onLoad, false);
  11.  
  12. function onClose(){
  13.     window.opener.setTimeout('performancingUI.reLoadBlogs()', 1000, true);
  14.     return true;
  15. }
  16.  
  17. function onLoad(){
  18.     loadPerFormancingUtil(true);
  19. }
  20.  
  21. function onWizarPageShow(){
  22.     enableNext();
  23.     enableBack();
  24.     return true;
  25. }
  26.  
  27. function onAutoNext(){
  28.     if(!gAutoReturn){
  29.         doCheckURL();
  30.         return false;
  31.     }else{
  32.         return true
  33.     }
  34. }
  35.  
  36. function doCheckURL(){
  37.     var isValid = checkURL();
  38.     var autoDetectDeck = document.getElementById("autodetect-deck");
  39.     if(isValid){
  40.         enableNext();
  41.         autoDetectDeck.selectedIndex = "2";
  42.     }else{
  43.         //autoDetectDeck.selectedIndex = "3";
  44.         doServerAPICheck();
  45.     }
  46.     gAutoReturn = true;
  47. }
  48.  
  49. function goTo( aWizard ){
  50.     document.getElementById('performancing-account-wizard').goTo(aWizard);
  51. }
  52.  
  53. function tryAgain(){
  54.     var autoDetectDeck = document.getElementById("autodetect-deck");
  55.     autoDetectDeck.selectedIndex = "0";
  56. }
  57.  
  58. function checkURL(){
  59.     var isStandard = checkForStandardURL();
  60.     var autoDetectDeck = document.getElementById("autodetect-deck");
  61.     autoDetectDeck.selectedIndex = "1";
  62.     if(isStandard){
  63.         document.getElementById('performancing-account-wizard').getPageById('start').next = "start2";
  64.         enableNext();
  65.         return true;
  66.     }
  67. }
  68.  
  69. function checkForStandardURL(){
  70.     var theDomain = document.getElementById("blog-url").value;
  71.     var serviceList = document.getElementById("performancing-blogservice-list");
  72.     //var customServiceList = document.getElementById('performancing-blogservice-custom-list');
  73.     var theSelectedBlogIndex = null;
  74.     var isStandard = false;
  75.     /*if(theDomain.search(/.blogspot.com/) != -1){ //Old Blogger Support
  76.         theSelectedBlogIndex = "0";
  77.         isStandard = true;
  78.     //}else
  79.     if(theDomain.search(/.wordpress.com/) != -1){
  80.         theSelectedBlogIndex = "0";
  81.         isStandard = true;
  82.     }else*/ if(theDomain.search(/.typepad.com/) != -1 || theDomain.search(/.blogs.com/) != -1){
  83.         theSelectedBlogIndex = "1";
  84.         isStandard = true;
  85.     }else if(theDomain.search(/livejournal.com/) != -1){
  86.         theSelectedBlogIndex = "2";
  87.         isStandard = true;
  88.     }else if(theDomain.search(/spaces.msn.com/) != -1 || theDomain.search(/spaces.live.com/) != -1){
  89.         theSelectedBlogIndex = "3";
  90.         isStandard = true;
  91.     }else if(theDomain.search(/performancing.com/) != -1){
  92.         theSelectedBlogIndex = "4";
  93.         isStandard = true;
  94.     }else if(theDomain.search(/jeeran.com/) != -1){
  95.         theSelectedBlogIndex = "5";
  96.         isStandard = true;
  97.     }
  98.     if(isStandard){
  99.         serviceList.selectedIndex = theSelectedBlogIndex;
  100.         return true;
  101.     }else{
  102.         return false;
  103.     }
  104. }
  105.  
  106. //Check to see if they accepted the terms of service
  107. //Check to see if we need to show the custom settings window
  108. function checkForAcceptedTOS(){
  109.     var acceptBox = document.getElementById('pff-license-check');
  110.     if(acceptBox.checked){
  111.         return true;
  112.     }else{
  113.         var errorMessage = performancingUI.getLocaleString('accounttoserror', []);
  114.         alert(errorMessage);
  115.         return false;
  116.     }
  117. }
  118.  
  119. function loadTOS(aService){
  120.     var theText = "";
  121.     if(aService == "performancing_com"){
  122.         //perfaccounttos
  123.         theText = performancingUI.getLocaleString('perfaccounttos');
  124.     }
  125.     var winAboout = document.getElementById("performancing-aw-tos-frame");
  126.     winAboout.contentWindow.document.body.innerHTML = theText;
  127. }
  128.  
  129.  
  130. //Check to see if we need to show the custom settings window
  131. function checkForCustom(){
  132.     var serviceList = document.getElementById('performancing-blogservice-list');
  133.     var aService = serviceList.selectedItem.value;
  134.     if( aService.match("_cust") ){
  135.          //document.getElementById('performancing-account-wizard').advance("login-custom");
  136.          document.getElementById('performancing-account-wizard').getPageById('start2').next = "login-custom";
  137.          return true;
  138.     }else if(aService == 'livejournal_com'){
  139.         var localeString = performancingUI.getLocaleString('awlivejournalsupport', []);
  140.         alert(localeString);
  141.     }else if(aService == 'performancing_com'){
  142.         loadTOS(aService);
  143.         document.getElementById('performancing-account-wizard').getPageById('start2').next = "doTOSConfirm";
  144.         return true;
  145.     }
  146.     return true;
  147. }
  148.  
  149. function tryServiceLogin(){
  150.     var serviceList = document.getElementById('performancing-blogservice-list');
  151.     var aService = serviceList.selectedItem.value;
  152.     var aServiceAPI = serviceList.selectedItem.getAttribute("api");
  153.     
  154.     var customServiceList = document.getElementById('performancing-blogservice-custom-list');
  155.     var aCustomService = customServiceList.selectedItem.value;
  156.     var aCustomServiceAPI = customServiceList.selectedItem.getAttribute("api");
  157.     var theApiInUse = null;
  158.     var username = document.getElementById('username').value;
  159.     var password = document.getElementById('password').value;
  160.     var custAPIURL = document.getElementById('custom-apiurl').value;
  161.     var custAPKey = document.getElementById('custom-appkey').value; //custAPIURL custAPKey
  162.  
  163.     if(username != "" && password != ""){
  164.         var isAtom = false;
  165.         document.getElementById("login-error-msg").hidden = true;
  166.         var loginSuccess = false;
  167.         var myWizardBlog = null;
  168.         var url = null;
  169.         var blogType = null;
  170.         var blogAPI = null;
  171.         var APIURL = null;
  172.         var APPKey = null;
  173.         var myWizardBlog = null;
  174.         //aService = 'blogger_com';
  175.         dump("Service Chosen: " + aService + "\n")
  176.         
  177.         if( aService.match("_cust") ){
  178.             theApiInUse = aCustomServiceAPI;
  179.         }else{
  180.             theApiInUse = aServiceAPI;
  181.         }
  182.         
  183.         switch(theApiInUse){
  184.             case "s_atom": //https://blogger.com/atom
  185.                 blogAPI = serviceList.selectedItem.getAttribute("api");
  186.                 APIURL = serviceList.selectedItem.getAttribute("apiurl");
  187.                 blogType = aService;          
  188.                 APPKey = serviceList.selectedItem.getAttribute("apikey");
  189.                 myWizardBlog = new perFormancingAtomAPI();
  190.                 isAtom = true;
  191.                 break;
  192.                 
  193.             case "s_mt":
  194.                 blogAPI = serviceList.selectedItem.getAttribute("api");
  195.                 APIURL = serviceList.selectedItem.getAttribute("apiurl");
  196.                 blogType = aService;          
  197.                 APPKey = serviceList.selectedItem.getAttribute("apikey");
  198.                 myWizardBlog = new perFormancingMovableTypeAPI();
  199.                 break;
  200.                 
  201.             case "s_blogger":
  202.                 blogAPI = serviceList.selectedItem.getAttribute("api");
  203.                 APIURL = serviceList.selectedItem.getAttribute("apiurl");
  204.                 blogType = aService;          
  205.                 APPKey = serviceList.selectedItem.getAttribute("apikey");
  206.                 myWizardBlog = new perFormancingBloggerAPI();
  207.                 break;
  208.                 
  209.             case "s_metaweblog":
  210.                 blogAPI = serviceList.selectedItem.getAttribute("api");
  211.                 APIURL = serviceList.selectedItem.getAttribute("apiurl");
  212.                 blogType = aService;          
  213.                 APPKey = serviceList.selectedItem.getAttribute("apikey");
  214.                 myWizardBlog = new performancingMetaweblogAPI();
  215.                 break;
  216.                 
  217.             //Start Custom/Standard API's
  218.             
  219.             case "atom": //https://blogger.com/atom
  220.                 blogAPI = customServiceList.selectedItem.getAttribute("api");
  221.                 APIURL = custAPIURL;
  222.                 blogType = aCustomService;
  223.                 APPKey = custAPKey;
  224.                 myWizardBlog = new perFormancingAtomAPI();
  225.                 isAtom = true;
  226.                 break;
  227.                 
  228.             case "atom_blogger": //https://blogger.com/ Beta
  229.                 blogAPI = customServiceList.selectedItem.getAttribute("api");
  230.                 APIURL = custAPIURL;
  231.                 blogType = aCustomService;
  232.                 APPKey = custAPKey;
  233.                 myWizardBlog = new perFormancingBloggerAtomAPI();
  234.                 isAtom = true;
  235.                 break;
  236.                 
  237.             case "mt":
  238.                 blogAPI = customServiceList.selectedItem.getAttribute("api");
  239.                 APIURL = custAPIURL;
  240.                 blogType = aCustomService;
  241.                 APPKey = custAPKey;
  242.                 myWizardBlog = new perFormancingMovableTypeAPI();
  243.                 break;
  244.                 
  245.             case "blogger":
  246.                 blogAPI = customServiceList.selectedItem.getAttribute("api");
  247.                 APIURL = custAPIURL;
  248.                 blogType = aCustomService;
  249.                 APPKey = custAPKey;
  250.                 myWizardBlog = new perFormancingBloggerAPI();
  251.                 break;
  252.                 
  253.             case "metaweblog":
  254.                 blogAPI = customServiceList.selectedItem.getAttribute("api");
  255.                 APIURL = custAPIURL;
  256.                 blogType = aCustomService;
  257.                 APPKey = custAPKey;
  258.                 myWizardBlog = new performancingMetaweblogAPI();
  259.                 break;
  260.                 
  261.             default:
  262.                 var localeString = performancingUI.getLocaleString('awnoservicechosen', []);
  263.                 alert(localeString);
  264.                 break;
  265.         }
  266.         
  267.         APIURL = APIURL.replace("_USER_NAME_", username);
  268.         APPKey = custAPKey;
  269.         
  270.         //case blogger
  271.         myWizardBlog.doSetup();
  272.         myWizardBlog.init(blogType, APPKey, APIURL, null, null, username,  password, false  );
  273.         //Setup temp object
  274.         gTempBlogObject.blogtype = blogType;
  275.         gTempBlogObject.blogapi = blogAPI;
  276.         gTempBlogObject.apiurl = APIURL;
  277.         gTempBlogObject.appkey = APPKey;
  278.         
  279.         var xmlStringMessageToSend = myWizardBlog.getUsersBlogs();
  280.         dump("XML to Send\n" + xmlStringMessageToSend + "\n");
  281.         if(!isAtom){
  282.             performancing_xmlcall.sendCommand(APIURL, xmlStringMessageToSend, 'accountwizard', "", "", performancing_xmlcall.processData);
  283.             setLoginTimeOut();
  284.         }
  285.         
  286.         return true;
  287.     }else{
  288.         document.getElementById("login-error-msg").hidden = false;
  289.         
  290.         return false;
  291.     }
  292. }
  293.  
  294. function tryServiceSelection(){
  295.     var serviceList = document.getElementById('performancing-wizard-blog-list');
  296.     
  297.     if (serviceList.selectedCount > 0) {
  298.             gSelectedBlogs = serviceList.selectedItems;
  299.             return true;
  300.     }
  301.     else{
  302.         var localeString = performancingUI.getLocaleString('selectablog', []);
  303.         alert(localeString);
  304.         return false;
  305.     }
  306. }
  307.  
  308.  
  309. function disableNext(){
  310.     document.getElementById('performancing-account-wizard').getButton('next').disabled = true;
  311.     return true;
  312. }
  313.  
  314. function enableNext(){
  315.     document.getElementById('performancing-account-wizard').getButton('next').disabled = false;
  316.     return true;
  317. }
  318.  
  319. function disableBack(){
  320.     document.getElementById('performancing-account-wizard').getButton('back').disabled = true;
  321.     return true;
  322. }
  323.  
  324. function enableBack(){
  325.     document.getElementById('performancing-account-wizard').getButton('back').disabled = false;
  326.     return true;
  327. }
  328.  
  329. function processReturnData(theObject, isAtom, theXML){
  330.     gPffDebugTemp.push(theObject);
  331.     gPffDebugTemp.push(theXML);
  332.     clearLoginTimeOut();
  333.     var isError = true;
  334.     if(theObject.length == null){
  335.         if(!isAtom){
  336.             if(theObject.faultString){
  337.                 dump("\nLogin Error: " + theObject.faultString + "\n")
  338.                 isError = true;
  339.             }else{
  340.                 dump('\nError: Unknown State\n');
  341.                 isError = true;
  342.             }
  343.         }
  344.     }else{
  345.         isError = false;
  346.         dump("\nLogin Success!\n")
  347.         dump("Response Length: "+theObject.length + "\n");
  348.         
  349.         gBlogObject = theObject;
  350.         dump("Response Length: "+gBlogObject.length + "\n");
  351.         clearListOut();
  352.         var tempArray = [];
  353.         for(j = 0; j < gBlogObject.length; j++){
  354.             var blogName = gBlogObject[j].blogName; 
  355.             var blogURL = gBlogObject[j].url;
  356.             var theGUID = newGuid();
  357.             var theBlogID = gBlogObject[j].blogid;
  358.             
  359.             addItemToList(blogName, blogURL, j, theGUID, theBlogID );
  360.         }
  361.  
  362.         var serviceList = document.getElementById('performancing-wizard-blog-list');
  363.         
  364.         if (serviceList.getRowCount() == 0){
  365.             isError = true;
  366.         }
  367.         else {
  368.             if( serviceList.selectedCount == 0) {
  369.                 serviceList.invertSelection();
  370.                 }
  371.         }
  372.     }
  373.     
  374.     if(!isError){
  375.         //document.getElementById('performancing-account-wizard').getPageById('login').next = "finish";
  376.         document.getElementById('performancing-account-wizard').advance("success");
  377.         return true;
  378.     }else{
  379.          //document.getElementById('performancing-account-wizard').getPageById('login').next = "login-error";
  380.          document.getElementById('performancing-account-wizard').advance("login-error");
  381.          return true;
  382.     }
  383. }
  384.  
  385. function gotoLoginPage(){
  386.     document.getElementById('performancing-account-wizard').goTo("login");
  387.     return false;
  388. }
  389.  
  390. /*
  391. // Original function by Lewis E. Moten III
  392. // Terms of Agreement:   
  393. // By using this code, you agree to the following terms...   
  394. // 1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
  395. // 2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  396. // 3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  397. // 4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
  398. */
  399. function newGuid() { 
  400.     var g = ""; 
  401.     for(var i = 0; i < 32; i++){
  402.         g += Math.floor(Math.random() * 0xF).toString(0xF) + (i == 8 || i == 12 || i == 16 || i == 20 ? "-" : ""); 
  403.     }
  404.     return g;
  405. }
  406. ////////////////////
  407.  
  408. function saveBlogToSprefs(){
  409.     var result = false;
  410.     var tempGUID = [];
  411.     //gSelectedBlogs
  412.     if(gSelectedBlogs.length > 0){
  413.         
  414.         for(var i=0; i < gSelectedBlogs.length; i++){
  415.             //
  416.             var theBlogName = gSelectedBlogs[i].getAttribute('blogname');
  417.             var theGUID = gSelectedBlogs[i].getAttribute('blogguid');
  418.             var theURL = gSelectedBlogs[i].getAttribute('blogurl');
  419.             var theBlogID = gSelectedBlogs[i].getAttribute('blogid');
  420.             //
  421.             
  422.             var theBlogType = gTempBlogObject.blogtype;
  423.             var theBlogAPI = gTempBlogObject.blogapi;
  424.             var theAppKey = gTempBlogObject.appkey;
  425.             var theAPIURL = gTempBlogObject.apiurl;
  426.             
  427.             var theUserName = document.getElementById('username').value;
  428.             var thePassWord = document.getElementById('password').value;
  429.             var useBoolean = document.getElementById('useBooleanForPublish').checked;
  430.             
  431.             //First 3 are for legacy support (v1.0)
  432.             if(theBlogType == "blogger_com" || theBlogType == "atom_cust" || theBlogType == "livejournal_atom_com" || theBlogType == "s_atom" || theBlogType == "atom" || theBlogType == "__atom_blogger"){
  433.                 theAPIURL = gBlogObject[i].url;
  434.             }                                                                                                                 
  435.             
  436.             var theAppKey = gTempBlogObject.appkey;
  437.             
  438.             result = generateXML(theBlogName, theBlogType, theAppKey, theUserName, theAPIURL, theGUID, theURL, theBlogID, theBlogAPI, useBoolean  );
  439.             
  440.             //Now save the username and password based on username and url
  441.             var addedUser = gPerformancingUtil.usermanagment.storeLoginDetails(theUserName, thePassWord, theURL);
  442.         }
  443.         
  444.         if(!result){
  445.             var localeString = performancingUI.getLocaleString('awerrorsavingbloginfo', []);
  446.             alert(localeString);
  447.         }
  448.         
  449.         if(!addedUser){
  450.                 var localeString = performancingUI.getLocaleString('awerrorsavinglogininfo', []);
  451.                 alert(localeString);
  452.         }
  453.         
  454.         //refresh the opener page
  455.         //window.opener.setTimeout(performancingUI.reLoadBlogs, 1000, true);
  456.         //disable the back button
  457.         document.getElementById('performancing-account-wizard').getButton('back').disabled = true;
  458.     }
  459. }
  460.  
  461. function generateXML(theBlogName, theBlogType, theAppKey, theUserName, theAPIURL, theGUID, theURL, theBlogID, theBlogAPI, useBoolean ){
  462.     //We need to get this from a file and theBlogXML = new XML(theFilesStringContents);
  463.     var file = getXMLFile();
  464.     var theXMLFile = null;
  465.     var theBlogXML = null;
  466.     //Doesn't exist, so let's create it.
  467.     if(!file.exists()){
  468.         dump('Creating file: ' + bloglistxmlfile + "\n");
  469.         theBlogXML = <bloglist>
  470.                         <defaults>
  471.                             <lastselected></lastselected>
  472.                         </defaults>
  473.                         <blogs></blogs>
  474.                      </bloglist>;
  475.         PerFormancingFileIO.create(file);
  476.         var rv = PerFormancingFileIO.write(file, theBlogXML.toString(), "w", "UTF-8");
  477.         if(!rv) {
  478.             var localeString = performancingUI.getLocaleString('cannotwritetofile', []);
  479.             alert(localeString);
  480.         }
  481.     }
  482.     
  483.     if(file.exists()){
  484.         var theXMLFile = PerFormancingFileIO.open(file.path);
  485.         var theXMLString = PerFormancingFileIO.read(theXMLFile, "UTF-8");
  486.         theBlogXML = new XML(theXMLString);
  487.         
  488.         //The Content for each Blog
  489.         theBlogXML.blogs.blog +=
  490.                                     <blog>
  491.                                         <blogname>{theBlogName}</blogname>
  492.                                         <blogtype>{theBlogType}</blogtype>
  493.                                         <blogapi>{theBlogAPI}</blogapi>
  494.                                         <appkey>{theAppKey}</appkey>
  495.                                         <username>{theUserName}</username>
  496.                                         <apiurl>{theAPIURL}</apiurl>
  497.                                         <GUID>{theGUID}</GUID>
  498.                                         <url>{theURL}</url>
  499.                                         <blogid>{theBlogID}</blogid>
  500.                                         <useboolean>{useBoolean}</useboolean>
  501.                                     </blog>;
  502.         //Write to file (save changes)
  503.         var newWrite = PerFormancingFileIO.write(file, theBlogXML.toString(), "w", "UTF-8");
  504.         if(!newWrite) {
  505.             var localeString = performancingUI.getLocaleString('cannotwritetofile', []);
  506.             alert(localeString);
  507.         }
  508.                                 
  509.         return theBlogXML;
  510.     }else{
  511.         return false;
  512.     }
  513. }
  514.  
  515. function deleteBlogEntry(theGUID, theXML){
  516.     var file = getXMLFile();
  517.     var theXMLString = PerFormancingFileIO.read(file, "UTF-8");
  518.     var theBlogXML = new XML(file);
  519.     //delete dude..blog.(GUID == theGUID);
  520.     var entryIndex = theBlogXML.blogs.blog.(GUID == theGUID ).childIndex();
  521.     delete theBlogXML.blogs.blog[entryIndex];
  522.     
  523. }
  524.  
  525. function getXMLFile(){
  526.     var file = PerFormancingDirIO.get("ProfD");
  527.     file.append("extensions");
  528.     file.append(bloglistxmlfile);
  529.     var theBlogXML = null;
  530.     
  531.     return file;
  532. }
  533.  
  534. function clearListOut(){
  535.     var list=document.getElementById('performancing-wizard-blog-list');
  536.     while(list.getRowCount() > 0){
  537.         list.removeItemAt( list.getRowCount() - 1);
  538.     }
  539. }
  540.  
  541. function addItemToList(theBlogName, theURL, number, theGUID, theBlogID){
  542.     var list = document.getElementById('performancing-wizard-blog-list');
  543.     var item = document.createElement('listitem');
  544.     item.setAttribute('id', 'blog-' + number);
  545.     item.setAttribute('blogname', theBlogName);
  546.     item.setAttribute('blogguid', theGUID);
  547.     item.setAttribute('blogurl', theURL);
  548.     item.setAttribute('blogid', theBlogID);
  549.     
  550.     var itemCell = document.createElement('listcell');
  551.     itemCell.setAttribute('label', theBlogName);
  552.     item.appendChild(itemCell);
  553.     
  554.     var itemCell2 = document.createElement('listcell');
  555.     itemCell2.setAttribute('label', theURL);
  556.     item.appendChild(itemCell2);
  557.     
  558.     //Append the elements
  559.     list.appendChild(item);
  560.     //sizeToContent();
  561. }
  562.  
  563.  
  564. function onCustomListClick(){
  565.     var customServiceList = document.getElementById('performancing-blogservice-custom-list');
  566.     var aCustomServiceAPI = customServiceList.selectedItem.getAttribute("apiurl");
  567.     var customAPIBox = document.getElementById('custom-apiurl');
  568.     customAPIBox.value = aCustomServiceAPI;
  569.     
  570.     if(customServiceList.selectedItem.value == 'roller_cust'){
  571.         var localeString = performancingUI.getLocaleString('awrollersupport', []);
  572.         alert(localeString);
  573.     }
  574.     if( customServiceList.selectedItem.getAttribute("useBoolean") == 'true'){
  575.         document.getElementById('useBooleanForPublish').checked = true;
  576.     }else{
  577.         document.getElementById('useBooleanForPublish').checked = false;
  578.     }
  579. }
  580.  
  581. function setLoginTimeOut(){
  582.     gPffAccountTimeOut = window.setTimeout("onLoginTimeOut()", 15000);
  583. }
  584.  
  585. function clearLoginTimeOut(){
  586.     window.clearTimeout(gPffAccountTimeOut);
  587. }
  588.  
  589. function onLoginTimeOut(){
  590.     document.getElementById('performancing-account-wizard').advance('login-error');
  591. }
  592.  
  593. function doServerAPICheck(){
  594.     var theDomain = document.getElementById("blog-url").value;
  595.     
  596.     //Make sure it's a valid URL:
  597.     if( theDomain.search("http://") == "-1" && theDomain.search("https://") == "-1"){
  598.         theDomain = "http://" + theDomain;
  599.     }
  600.     //gMakeXMLCall3(theDomain, "1", "accountw-autodetect", "", "");
  601.     var theCall = new PffXmlHttpReq(theDomain, "GET", null, false, null, null);
  602.     
  603.     theCall.onResult = function( aText, aXML ){
  604.         doProssessAutoDetectPage("1", aText, "1");
  605.     }
  606.     theCall.onError = function (aStatusMsg, Msg) {
  607.         //foo
  608.     }
  609.     theCall.prepCall(); //Set up The call (open connection, etc.)
  610.     theCall.request.setRequestHeader("Content-Type", "text/xml");
  611.     theCall.makeCall(); //Make the call
  612.     theCall.request.overrideMimeType ('text/xml');
  613. }
  614.  
  615. function doProssessAutoDetectPage(aType, theXMLData, aNum){
  616.     var autoDetectDeck = document.getElementById("autodetect-deck");
  617.     try{
  618.         var theResult = null;
  619.         if(aNum == "1"){
  620.             try{
  621.                 //theResult = prossessAutoDetectPage( aType, theXMLData );
  622.                 theResult = prossessAutoDetectPageText( aType, theXMLData );
  623.             }catch(e){
  624.                 alert("Error, malformed html, cannot auto-detect blog.\nPlease visit the ScribeFire Support Forums for help:\nhttp://performancing.com/forum/firefox/");
  625.             }
  626.         }else{
  627.             theResult = prossessAutoDetectPage2( aType, theXMLData );
  628.         }
  629.         //gTempFeedback = theResult;
  630.         if(theResult[0]){
  631.                 var customServiceList = document.getElementById('performancing-blogservice-custom-list');
  632.                 var theSelectedBlogIndex = null;
  633.                 var theAPI = theResult[1];
  634.                 var theURL = theResult[2];
  635.                 switch(theAPI){
  636.                     case "wordpress":
  637.                         customServiceList.selectedIndex = "0";
  638.                         //tryServiceLogin(true, theURL, "metaweblog" );
  639.                         break;
  640.                         
  641.                     case "blogger":
  642.                         //customServiceList.selectedIndex = "5";
  643.                         //tryServiceLogin(true, theURL, "atom" );
  644.                         break;
  645.                     
  646.                     case "blogger_beta":
  647.                         customServiceList.selectedIndex = "6";
  648.                         //tryServiceLogin(true, theURL, "atom" );
  649.                         break;
  650.                     
  651.                     case "metaweblog":
  652.                         customServiceList.selectedIndex = "5";
  653.                         //tryServiceLogin(true, theURL, "metaweblog" );
  654.                         break;
  655.                         
  656.                     case "movabletype":
  657.                         customServiceList.selectedIndex = "1";
  658.                         //tryServiceLogin(true, theURL, "mt" );
  659.                         break;
  660.                 }
  661.             var serviceList = document.getElementById('performancing-blogservice-list');
  662.             serviceList.selectedItem.value = "_custom"
  663.             onCustomListClick();
  664.             var custAPIURL = document.getElementById('custom-apiurl');
  665.             //var custAPKey = document.getElementById('custom-appkey');
  666.             custAPIURL.value = theURL;
  667.             document.getElementById('performancing-account-wizard').getPageById('start').next = "login-custom";
  668.             document.getElementById('performancing-account-wizard').advance('login-custom');
  669.             document.getElementById('performancing-account-wizard').getPageById('login-custom').back = "start";
  670.             enableNext();
  671.             autoDetectDeck.selectedIndex = "0";
  672.         }else{
  673.             //alert("Result Error");
  674.             autoDetectDeck.selectedIndex = "3";
  675.         }
  676.     }catch(e){
  677.         autoDetectDeck.selectedIndex = "3";
  678.     }
  679. }
  680.  
  681. // GPL function originally by Flock
  682. // No longer used, now using REGEXP
  683. function prossessAutoDetectPage(aType, theXMLData){
  684.     //alert("Cool : " + aType);
  685.     gPffDebugTemp.push(theXMLData);//isBlogger = gPffDebugTemp[0].match( /(?:href\=\".*)(http\:\/\/\.*.blogger.com\/feeds\/\d+\/posts\/full)/ );
  686.     var autoDetectDeck = document.getElementById("autodetect-deck");
  687.     try{
  688.         
  689.         var properHeader = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
  690.         var text = properHeader + "\n" + "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head>\n"
  691.     
  692.         
  693.         var title_html = "";
  694.         if(theXMLData.match(/(<title.*>.+?>)/))
  695.         {
  696.             title_html = RegExp.$1;
  697.         }
  698.         text += title_html;
  699.     
  700.         var R = /<link.+?>/g;
  701.         for(;;)
  702.         {
  703.             var ar = R.exec(theXMLData);
  704.             if(!ar) break;
  705.             var cur = ar[0] + "";
  706.             if(!cur.match(/\/>/))
  707.             {
  708.               cur = cur.replace(/>/,"/>");
  709.             }
  710.             text += cur + "\n";
  711.         }
  712.         text += "</head></html>";
  713.         var parser = new DOMParser();
  714.         var resultDoc = parser.parseFromString(text,"text/xml");        
  715.         //gTempFeedback = resultDoc;
  716.             var linklist = resultDoc.getElementsByTagName("link");
  717.             for(var i=0;i<linklist.length;++i)
  718.             {
  719.                 var link = linklist[i]; 
  720.                 var url = link.href;
  721.                 if(!url) continue;
  722.                 
  723.                 if(link.type=="application/atom+xml" && link.rel=="service.post")
  724.                 {
  725.                     /*
  726.                      * Blogger Atom API, what else
  727.                      */
  728.                      //(blogger.com\/feeds\/\d+\/posts\/full)
  729.                      //var theRegExp = /(blogger.com\/feeds\/\d+\/posts\/)/;
  730.                      //posts/full
  731.                      var theRegExp = /(\/posts\/full)/;
  732.                      if( theRegExp.test(url) ){
  733.                          return [true, "blogger_beta", url];
  734.                      }else{
  735.                         //return [true, "blogger", url]; //Old Blogger
  736.                      }
  737.         
  738.                 }
  739.                 else if(link.rel=="pingback")
  740.                 {
  741.                     /*
  742.                      * Wordpress, what else
  743.                      */
  744.                      return [true, "wordpress", url];
  745.                 }
  746.                 else if(link.title=="RSD")
  747.                 {
  748.                     /*
  749.                      * Blogger xml-rpc service discovery
  750.                      */
  751.                     //inst.doRequest(listener, url, inst.onIntrospect);
  752.                     //if(aType == "1"){
  753.                         doSecondCall(url);
  754.                     //}else{
  755.                     //    return [false, "error"];
  756.                     //}
  757.                 }
  758.             }
  759.     }catch(e){
  760.         autoDetectDeck.selectedIndex = "3";
  761.         //alert("Error: " + e);
  762.     }
  763.     return [false, "error"];
  764. }
  765.  
  766. function prossessAutoDetectPageText(aType, theXMLData){
  767.     gPffDebugTemp.push(theXMLData);
  768.     //Blogger Beta
  769.     //var isBlogger = theXMLData.match( /(?:href\=\".*)(http\:\/\/.*blogger.com\/feeds\/\d+\/posts\/)/ );
  770.     //var isBlogger = theXMLData.match( /(?:\<link\s*rel\=\"service.post\"\s*type\=\"\application\/atom\+xml\"\s*title\=\"\D*\S*\"\s*href=\")(.*posts\/)(?=.*\")/ );
  771.     //var isBloggerBeta = theXMLData.match( /(?:\<link\s*rel\=\"alternate\"\s*type\=\"\application\/atom\+xml\"\s*title\=\"\D*\S*\"\s*href=\")(.*\/feeds\/posts\/\w+)(?=\")/ );
  772.     var isBloggerBeta = theXMLData.match( /(?:\<link\s*rel\=\"alternate\"\s*type\=\"\application\/atom\+xml\"\s*title\=\"\S*\D*\S*\"\s*href=\")(.*\/feeds\/posts\/\w+)(?=\")/ );
  773.     if(isBloggerBeta){
  774.         return [true, "blogger_beta", isBloggerBeta[1]];
  775.     }
  776.     
  777.     var isBlogger = theXMLData.match( /(?:\<link\s*rel\=\"service.post\"\s*type\=\"\application\/atom\+xml\"\s*title\=\"\D*\S*\"\s*href=\")(.*posts\/\w*)(?=.*\")/ );
  778.     if(isBlogger){
  779.         isBlogger[1] = isBlogger[1].replace("summary", "full");
  780.         return [true, "blogger_beta", isBlogger[1]];
  781.     }
  782.     //WordPress
  783.     //(?:\<link\.*\s*rel\=\"pingback\"\s*href=\")(.*)(?=\")
  784.     var isWordPress = theXMLData.match( /(?:\<link[\s*\S*\s*]*rel\=\"pingback\"[\s]*href=\")(.*)(?=\")/ );
  785.     if(isWordPress) return [true, "wordpress", isWordPress[1]];
  786.     
  787.     //RSD
  788.     //(?:title\=\"RSD\"\s*\.*href=\")(.*)(?=\")
  789.     var isRSD = theXMLData.match( /(?:\<link[\s*\S*\s*]*title\=\"RSD\"\s*\.*href=\")(.*)(?=\")/ );
  790.     if(isRSD) doSecondCall(isRSD[1]);
  791.     
  792.     
  793. }
  794.  
  795. function doSecondCall(aURL){
  796.     //gMakeXMLCall3(aURL, "2", "accountw-autodetect-2", "", "");
  797.     var theCall = new PffXmlHttpReq(aURL, "GET", null, false, null, null);
  798.     
  799.     theCall.onResult = function( aText, aXML ){
  800.         doProssessAutoDetectPage("2", aXML, "2");
  801.     }
  802.     theCall.onError = function (aStatusMsg, Msg) {
  803.         //foo
  804.     }
  805.     theCall.prepCall(); //Set up The call (open connection, etc.)
  806.     theCall.request.setRequestHeader("Content-Type", "text/xml");
  807.     theCall.makeCall(); //Make the call
  808.     theCall.request.overrideMimeType ('text/xml');
  809.     
  810. }
  811.  
  812. // GPL function originally by Flock
  813. function prossessAutoDetectPage2(aType, theXMLData){
  814.         try{
  815.             //gPffDebugTemp.push(theXMLData);
  816.             var apis = theXMLData.getElementsByTagName("api");
  817.             //gPffDebugTemp.push(apis);
  818.             for(var i=0;i<apis.length;++i)
  819.             {
  820.                 var name = apis[i].getAttribute("name").toLowerCase();
  821.                 //if(name=="atom") continue;
  822.                 //if(name=="atom"){
  823.  
  824.                     var apiLink = apis[i].getAttribute("apiLink");
  825.                     var preferred = apis[i].getAttribute("preferred");
  826.                     var blogID = apis[i].getAttribute("blogID");
  827.                     var B = null;
  828.                     if(name=="blogger") {
  829.                         return [true, "blogger", apiLink];
  830.                     }
  831.                     if(name=="metaweblog") {
  832.                         return [true, "metaweblog", apiLink];
  833.                     }
  834.                     if(name=="movabletype") {
  835.                         return [true, "movabletype", apiLink];
  836.                     }
  837.                 //}
  838.             }
  839.             //listener.onAPI(rval);
  840.             return [false, "error"];
  841.         } 
  842.         catch(e) {
  843.             //alert(e + " " + e.fileName + " " + e.lineNumber);
  844.             return [false, "error"];
  845.         }
  846. }
  847.  
  848.